package ware.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feign.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import ware.domain.WareInfo;
import ware.service.WareInfoService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 仓库信息(WareInfo)表控制层
 *
 * @author panghu
 * @since 2023-03-04 21:11:29
 */
@RestController
@RequestMapping("ware/wareInfo")
public class WareInfoController {

    @Autowired
    private WareInfoService wareInfoService;

    @GetMapping("list")
    public R list(@RequestParam Map<String, Object> params) {
        Page<WareInfo> wareInfoPage = wareInfoService.querPage(params);
        return R.ok().put("data", wareInfoPage);
    }

    /**
     * 删除仓库
     *
     * @param ids
     * @return
     */
    @PostMapping("remove")
    public R removeCategory(@RequestBody Long[] ids) {
        boolean result = wareInfoService.removeBatchByIds(List.of(ids));
        return result ? R.ok("删除仓库成功") : R.error("删除仓库失败");
    }


    /**
     * 增加仓库
     *
     * @param wareInfo
     * @return
     */
    @PostMapping("save")
    public R save(@RequestBody WareInfo wareInfo) {
        boolean result = wareInfoService.save(wareInfo);
        return result ? R.ok("增加仓库成功") : R.error("增加仓库失败");
    }

    /**
     * 修改仓库
     *
     * @param wareInfo
     * @return
     */
    @PutMapping("update")
    public R edit(@RequestBody WareInfo wareInfo) {
        boolean result = wareInfoService.updateById(wareInfo);
        return result ? R.ok("修改仓库成功") : R.error("修改仓库失败");
    }


    /**
     * 获取单个仓库的数据
     *
     * @param id
     * @return
     */
    @GetMapping("info/{id}")
    public R info(@PathVariable Long id) {
        WareInfo wareInfo = wareInfoService.getById(id);
        return R.ok().put("data", wareInfo);
    }

}

